package com.freight.order.controller;

import com.freight.core.common.annotation.SystemLog;
import com.freight.core.common.enums.LogType;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.Result;
import com.freight.order.dto.OrderGoodsDto;
import com.freight.order.entity.OrderGoods;
import com.freight.order.service.CompanyOrderGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@Api(description = "货主端 --- 货源信息操作接口")
@RequestMapping("/freight/companyOrderGoods")
@Transactional
public class CompanyOrderGoodsController {

    @Autowired
    private CompanyOrderGoodsService companyOrderGoodsService;


    @RequestMapping(value = "/publis", method = RequestMethod.POST)
    @ApiOperation(value = "配置信息")
    public Result<OrderGoods> publis() {
        String res = companyOrderGoodsService.publis();
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/publicGoods", method = RequestMethod.POST)
    @ApiOperation(value = "发布货源需求")
    @SystemLog(description = "货主发布货源", type = LogType.OPERATION)
    public Result<OrderGoods> publicGoods(OrderGoodsDto orderGoodsDto) {
        String res = companyOrderGoodsService.publicGoods(orderGoodsDto);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/updateGoods", method = RequestMethod.POST)
    @ApiOperation(value = "修改货源信息")
    @SystemLog(description = "审核未通过，货主修改货源", type = LogType.OPERATION)
    public Result<OrderGoods> updateGoods(OrderGoodsDto orderGoodsDto,Long goodId) {
        String res = companyOrderGoodsService.updateGoods(orderGoodsDto,goodId);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/delGoods", method = RequestMethod.POST)
    @ApiOperation(value = "删除货源信息")
    @SystemLog(description = "货主删除货源", type = LogType.OPERATION)
    public Result<OrderGoods> delGoods(Long goodId) {
        String res = companyOrderGoodsService.delGoods(goodId);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/updateGoodsStatus", method = RequestMethod.POST)
    @ApiOperation(value = "修改货源状态 --- 关闭、开启、完结")
    @SystemLog(description = "货主修改货源状态", type = LogType.OPERATION)
    public Result<OrderGoods> updateGoodsStatus(Long goodId,Integer status) {
        String res = companyOrderGoodsService.updateGoodsStatus(goodId,status);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/delGoodsLists", method = RequestMethod.POST)
    @ApiOperation(value = "批量删除货源信息")
    @SystemLog(description = "货主删除货源", type = LogType.OPERATION)
    public Result<OrderGoods> delGoods(Long[] goodIds) {
        String res = companyOrderGoodsService.delGoodsList(goodIds);
        return ResultUtil.success(res);
    }

}
